package com.google.code.completenessaudit;

import java.util.List;
import java.util.ArrayList;

import com.google.code.completenessaudit.task.TaskInfos;
import com.google.code.completenessaudit.task.TasksList;
import com.google.code.completenessaudit.vcs.RevisionInfos;
import com.google.code.completenessaudit.vcs.SourceInfos;

public class ReleaseInfos {

	private Extracts extracts;
	private MergeResult mergeResult;

	public void merge() {
	    mergeResult = new MergeResult();
	    List<String> tasksDone = new ArrayList<String>();
	    for (TasksList tasksList : extracts.getTasksExtract()) {
	    	for (TaskInfos taskInfo : tasksList.getTasks()) {
	    		
	    		for (RevisionInfos revision : extracts.getVCSExtract()) {
	    			if (revision.containsTask(taskInfo.getId())) {
	    		        mergeResult.getUpdatableAgreedContent().add(new ReleaseItem(taskInfo));
	    		    } else {
	    		    	mergeResult.getUpdatableProblematicContent().add(new ReleaseItem(taskInfo));
	    		    }
	    		    tasksDone.add(taskInfo.getId());
	    		}
	    		
	    	}
	    }
	    
	
	    for (RevisionInfos revision : extracts.getVCSExtract()) {
	    	for (SourceInfos sourceInfo : revision.getSources()) {
	    		if( ! tasksDone.contains(sourceInfo.getTaskId())) {
	    			mergeResult.getUpdatableOrphanContent().add(new ReleaseSource(sourceInfo));        
	    		}
	    	}
		}
	}

	public Extracts getExtracts() {
		return extracts;
	}

	public void setExtracts(Extracts extracts) {
		this.extracts = extracts;
	}

	public MergeResult getMergeResult() {
		return mergeResult;
	}

	public void setMergeResult(MergeResult mergeResult) {
		this.mergeResult = mergeResult;
	}
}
